<!--
 * @Author: nns4
 * @Date: 2019-10-31 17:30:17
 * @LastEditors: nns4
 * @LastEditTime: 2020-04-23 09:50:47
 * @FilePath: /citciWechartShop/src/views/home/index.vue
 * @Description:   首页
 -->
<template>
  <div>
    <van-pull-refresh v-model="isLoading" @refresh="onRefresh">
      <van-list
        :immediate-check="false"
        :offset="200"
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="onLoad"
      >
        <van-cell v-for="item in list" :key="item" :title="item" />
      </van-list>
    </van-pull-refresh>
  </div>
</template>
<script>
export default {
  name: "home",
  data() {
    return {
      list: [],
      isLoading: false,
      loading: false,
      finished: false
    };
  },
  mounted() {
    this.onLoad();
  },
  methods: {
    onRefresh() {
      setTimeout(() => {
        this.isLoading = false;
        console.log("ok");
      }, 1000);
    },
    onLoad() {
      // 异步更新数据
      setTimeout(() => {
        for (let i = 0; i < 2; i++) {
          this.list.push(this.list.length + 1);
        }
        // 加载状态结束
        this.loading = false;
        // 数据全部加载完成
        if (this.list.length >= 60) {
          this.finished = true;
        }
      }, 500);
    }
  }
};
</script>
<style lang="less" scoped>
</style>